package com.konka.demo.controller;

import com.konka.demo.service.IDemoService;
import com.konka.spring.framework.annotation.Autowired;
import com.konka.spring.framework.annotation.Controller;
import com.konka.spring.framework.annotation.RequestMapping;
import com.konka.spring.framework.annotation.RequestParam;
import com.konka.spring.framework.webmvc.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author konka
 * @date 2023/2/7
 * @description:
 */
@Controller
@RequestMapping("/demo")
public class DemoController {

    @Autowired
    private IDemoService demoService;

    @RequestMapping("/query")
    public void query(HttpServletRequest request, HttpServletResponse response,
                    @RequestParam("name") String name){
        try {
            String result = demoService.queryName(name);
            response.getWriter().write(result);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    @RequestMapping("/index")
    public ModelAndView index(HttpServletRequest request, HttpServletResponse response,
                              @RequestParam("name") String name){
        Map<String, Object> model = new HashMap<>();
        model.put("teacher",name);
        model.put("data","111");
        model.put("token","123456");
        return new ModelAndView("index",model);
    }
}
